use Validation;

package ValidateMap;

@ISA = qw/Operation/;


sub init{
    my $self = shift;

    $self->dependencies(qw/LogManager MapManager/);
}


## Attempts to find a map under the key MAP
## If it can't, attempts to find the selected map through
## the map manager 
sub perform{
    my $self = shift;
    my $map = $self->params->{MAP};

    my $lm = $self->{LogManager};
    $lm->log($map."---".ref($map));

    # A map where the movement takes place, specified either directly
    # or the currently selected map within the MapManager
    if(! ((defined $map) and (ref $map eq 'Map')) ){
	my $selectedMap = $self->{MapManager}->selected;
	if(defined $selectedMap){
	    $self->params->{MAP} = $selectedMap;
    	    $lm->log((ref $self).": Selecting default Map: ".$selectedMap."---".ref($selectedMap));
	} else{
	    $lm->log((ref $self).": ERROR - No map defined and no map selected in map manager");

	    return ActionResult->new("FAILURE", "Map validation ERROR");
	}
    }
#    $lm->log(ref($self).": OK - Map found");
    return ActionResult->new("SUCCESS", "Map validation OK");
}

1;
